﻿#include "unrealircd.h"
#include "h.h"
CMD_FUNC(cmd_app);

ModuleHeader MOD_HEADER
= {
	"third/app",
	"1.1",
	"This module will add, delete, change, check and other operations to the database",
	"waitch",
	"unrealircd-5",
};

MOD_INIT()
{
	CommandAdd(modinfo->handle, "APP", cmd_app, 2, CMD_UNREGISTERED);
	

	return MOD_SUCCESS;
}

MOD_LOAD()
{
	return MOD_SUCCESS;
}

MOD_UNLOAD()
{
	return MOD_SUCCESS;
}

/**
 * @brief 系统设备验证
 * parv[1]: 验证码
 * parv[2]: 登录设备mac地址
 * 
 */
CMD_FUNC(cmd_app) {
	if (parc < 2 || BadPtr(parv[1])) {
		sendnumeric(client, ERR_NEEDMOREPARAMS, "APP");
		return;
	}
	if (strcmp("123456789", parv[1])) {
		sendnumeric(client, ERR_APPVALIDATION);
		exit_client(client, NULL, "not my app,deny to use");
		return;
	}
	if(parc >= 3 && !BadPtr(parv[2])){
		safe_strdup(client->mac,parv[2]);
	}
	if(!IsAPPIdent(client)){
		list_move(&client->lclient_node, &unlogined_client_list);
		irccounts.unknown--;
		irccounts.unlogin++;
		SetAPPIdent(client);
		SetUnlogin(client);
	}
	sendnumeric(client, SUCCESS, "APP");
}